{% extends 'admin/admin_base.html' %}
{% import "_macros.html" as macros %}

{% block title %}
    Blog_mini -博文分类
{% endblock %}

{% block admin_content %}
<div class="entry-box manage-articleTypes">
    <h4><strong>博文分类</strong></h4>
    <hr/>
    <p><span class="glyphicon glyphicon-book"></span>分类总数：<span class="badge">{{ ArticleType.query.count() }}</span></p>
    <div class="articleTypes-box">
        <ul class="nav nav-tabs">
            <li class="active"><a href="{{ url_for('admin.manage_articleTypes') }}">博文分类</a></li>
            <li class=""><a href="{{ url_for('admin.manage_articleTypes_nav') }}">分类导航</a></li>
        </ul>
        <div class="articleTypes" id="articleTypes">
            <table class="table table-striped table-hover">
                <thead>
                <tr class="table-header">
                    <th>分类名称</th>
                    <th>分类介绍</th>
                    <th>属性</th>
                    <th>所属导航</th>
                    <th>博文数量</th>
                    <th>修改</th>
                    <th>删除</th>
                </tr>
                </thead>
                <tbody>
                {% for articleType in articleTypes %}
                    <tr>
                        <td>
                            <a href="{{ url_for('main.articleTypes', id=articleType.id) }}" target="_blank">
                                {{ articleType.name }}
                            </a>
                        </td>
                        <td>
                            {% if articleType.introduction %}
                                {{ articleType.introduction }}
                            {% else %}
                                该分类暂时没有介绍
                            {% endif %}
                        </td>
                        <td>
                            {% if articleType.is_hide %}
                                隐藏
                            {% else %}
                                公开
                            {% endif %}
                        </td>
                        <td>
                            {% if articleType.menu %}
                                {{ articleType.menu.name }}
                            {% else %}
                                该分类暂时没有所属导航
                            {% endif %}
                        </td>
                        <td>{{ articleType.articles.count() }}</td>
                        <td>
                            <a class="btn" title="修改分类信息"
                               onclick="get_articleType_info('{{ url_for('admin.get_articleType_info', id=articleType.id) }}', {{ articleType.id }})">
                                <span class="glyphicon glyphicon-edit"></span>
                            </a>
                        </td>
                        <td>
                            <a class="btn btn-sm btn-default delete-articleType" title="删除分类"
                               onclick="delArticleTypeCfm('{{ url_for('admin.delete_articleType', id=articleType.id, page=page) }}')">
                                <span class="glyphicon glyphicon-trash"></span>
                            </a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        <div class="add-articleType">
            <a class="btn btn-sm btn-primary add-articleType-btn">
                <span class="glyphicon glyphicon-plus-sign"></span>
                添加分类
            </a>
        </div>
    </div>
    <div class="pagination">
        {{ macros.pagination_widget(pagination, endpoint) }}
    </div>
</div>

<!-- 信息删除确认: For add articleType form-->
<div class="modal fade" id="addArticleTypeFormModel">
    <div class="modal-dialog">
        <div class="modal-content message_align">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">×</span></button>
                <h4 class="modal-title">添加博文分类</h4>
            </div>
            <form id="addArticleTypeForm" method="post" action="">
                <div class="modal-body">
                        <div class="form-group">
                            {{ form.csrf_token }}
                            {{ form.name.label }}
                            {{ form.name(class='form-control', required='') }}
                            {{ form.setting_hide.label }}
                            {{ form.setting_hide(class='form-control', required='') }}
                            {{ form.introduction.label }}（可选）
                            {{ form.introduction(class='form-control') }}
                            {{ form.menus.label }}
                            {{ form.menus(class='form-control', required='') }}
                        </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button id="addArticlyTypeCfmClick" type="submit" class="btn btn-success">确定</button>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!-- 信息删除确认: For edit articleType form-->
<div class="modal fade" id="editArticleTypeFormModel">
    <div class="modal-dialog">
        <div class="modal-content message_align">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="ModalTitle"></h4>
            </div>
            <form id="editArticleTypeForm" method="post"
                  action="{{ url_for('admin.edit_articleType', page=page) }}">
                <div class="modal-body">
                        <div class="form-group">
                            {{ form2.csrf_token }}
                            {{ form2.articleType_id(type='hidden') }}
                            {{ form2.name.label }}
                            {{ form2.name(id='editName', class='form-control', required='') }}
                            {{ form2.setting_hide.label }}
                            {{ form2.setting_hide(id='editSetting_hide', class='form-control', required='') }}
                            {{ form2.introduction.label }}（可选）
                            {{ form2.introduction(id='editIntroduction', class='form-control') }}
                            {{ form2.menus.label }}
                            {{ form2.menus(id='editMenus', class='form-control', required='') }}
                        </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button id="editArticlyTypeCfmClick" type="submit" class="btn btn-success">确定</button>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!-- 信息删除确认: For delete an articletype confirm -->
<div class="modal fade" id="delArticleTypeCfmModel">
    <div class="modal-dialog">
        <div class="modal-content message_align">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">×</span></button>
                <h4 class="modal-title">确认删除分类？</h4>
            </div>
            <div class="modal-body">
                <p>
                    将该分类删除后不可恢复，同时会将该分类的所有博文设置为<strong>未分类</strong>，您确认要删除吗？
                </p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <a onclick="" id="delArticleTypeCfmClick" class="btn btn-success" data-dismiss="modal">确定</a>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{% endblock %}